﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace plc_Test1
{
    // 自定义消息框表单类
    public partial class CustomMessageBox : Form
    {
        private Label lblMessage;
        private Button btnOK;
        private PictureBox pbxIcon;

        public CustomMessageBox(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            InitializeComponent();
            this.Text = caption;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.ShowInTaskbar = false;

            lblMessage = new Label { Text = text, AutoSize = true, Location = new Point(50, 20) };
            pbxIcon = new PictureBox { Size = new Size(32, 32), Location = new Point(10, 10) };
            pbxIcon.Image = GetMessageBoxIcon(icon);

            switch (buttons)
            {
                case MessageBoxButtons.OK:
                    btnOK = new Button { Text = "确定", Location = new Point(110,60) };
                    btnOK.Click += (s, ev) => this.DialogResult = DialogResult.OK;
                    this.Controls.Add(btnOK);
                    break;
                    // 可以添加更多的按钮处理逻辑
            }

            this.Controls.Add(lblMessage);
            this.Controls.Add(pbxIcon);

            this.ClientSize = new Size(300, 100); // 可以根据需要调整大小
        }

        private Image GetMessageBoxIcon(MessageBoxIcon icon)
        {
            switch (icon)
            {
                case MessageBoxIcon.Information:
                    return SystemIcons.Information.ToBitmap();
                case MessageBoxIcon.Error:
                    return SystemIcons.Error.ToBitmap();
                case MessageBoxIcon.Warning:
                    return SystemIcons.Warning.ToBitmap();
                case MessageBoxIcon.Question:
                    return SystemIcons.Question.ToBitmap();
                default:
                    return null;
            }
        }

    }
}
